package first.codeTop.meituan;

public class Leetcode704 {
    // 二分查找
    public static void main(String[] args) {
        int[] nums = {-1,0,3,5,9,12};
        System.out.println(search(nums, 2));
    }

    public static int search(int[] nums, int target) {
        int i = 0;
        int j = nums.length-1;
        while (i <= j) {
            int tmp = (i+j) / 2;
            if (nums[tmp] > target) {
                j = tmp - 1;
            } else if (nums[tmp] < target) {
                i = tmp + 1;
            } else {
                return tmp;
            }
        }
        return -1;
    }
}
